<!-- 删除确认弹窗 -->
<template>
    <Modal
        class-name="no-border"
        :value="value"
        @input="handleInput"
        width="390"
        :closable="false"
    >
        <div slot="header">
            删除{{ title }}
            <Icon class="f-fr" type="ios-close" @click="closeModal"/>
        </div>
        <div class="clearfix">
            <div class="f-fl icon">
                <Icon type="md-close-circle"/>
            </div>
            <div class="f-fl modal-content">
                删除{{ title }}数据无法恢复,是否确认删除?
            </div>
        </div>
        <div slot="footer">
            <Button type="default" @click="closeModal">取消</Button>
            <Button type="primary" @click="deleteHandle">确定</Button>
        </div>
    </Modal>
</template>

<script>
import { delDeclare } from '@/api/declare'

export default {
    name: 'DeletePromptModal',
    props: {
        value: {
            default: false,
            type: Boolean
        },
        deletePrompt: {
            default: function () {
                return {
                    title: '',
                    type: '',
                    declareId: ''
                }
            },
            type: Object
        }
    },
    data () {
        return {
            title: '',
            type: '', // 报关单类型 JK-进口  CK-出口  JJ-进境  CJ-出境
            declareId: '',
            tagNavList: [] // 页签list
        }
    },
    created () {
        this.init(this.deletePrompt)
    },
    methods: {
        init (data) {
            console.log(data)
            this.title = data.title
            this.type = data.type // 报关单类型 JK-进口  CK-出口  JJ-进境  CJ-出境
            this.declareId = data.declareId
            this.tagNavList = this.$store.state.app.tagNavList
        },

        closeModal () {
            this.handleInput(false)
        },
        handleInput (v) {
            this.$emit('input', v)
        },

        deleteHandle () {
            switch (this.title) {
                case '报关单':
                    this.deleteCustoms(this.type)
                    break
                case '商品明细':
                    this.deleteGoodsItem(this.type)
                    break
                case '集装箱信息':
                    this.deleteContainerItem(this.type)
                    break
                case '单证信息':
                    this.deleteNumOfDocItem(this.type)
                    break
            }
        },

        // 删除报关单
        deleteCustoms (type) {
            let data = {
                declareIds: this.declareId
            }
            delDeclare(data).then(res => {
                if (res.data.code === '0000') {
                    this.$Message.success(res.data.msg)
                    this.closeModal()
                    this.routerJump(type)
                }
            })
        },

        // 路由跳转
        routerJump (type) {
            let currentRouter = '' // 当前删除的页面
            let goRouter = '' // 即将跳转的页面

            switch (type) {
                case 'JK':
                    currentRouter = 'declareimportadd'
                    goRouter = 'declareimport'
                    break
                case 'CK':
                    currentRouter = 'declareexportadd'
                    goRouter = 'declareexport'
                    break
                case 'JJ':
                    currentRouter = 'declareinputborderadd'
                    goRouter = 'declareinputborder'
                    break
                case 'CJ':
                    currentRouter = 'declareoutputborderadd'
                    goRouter = 'declareoutputborder'
                    break
            }

            this.tagNavList.forEach((item, index) => {
                if (item.name === currentRouter) {
                    this.tagNavList.splice(index, 1)
                }
            })
            this.$router.push({
                name: goRouter
            })
        },

        // 删除商品
        deleteGoodsItem (type) {
            switch (type) {
                case 'JK':
                    this.$emit('deleteJKGoodsItem', this.declareId)
                    this.closeModal()
                    break
                case 'CK':
                    this.$emit('deleteCKGoodsItem', this.declareId)
                    this.closeModal()
                    break
                case 'JJ':
                    this.$emit('deleteJKGoodsItem', this.declareId)
                    this.closeModal()
                    break
                case 'CJ':
                    this.$emit('deleteCKGoodsItem', this.declareId)
                    this.closeModal()
                    break
            }
        },

        // 删除集装箱
        deleteContainerItem (type) {
            switch (type) {
                case 'JK':
                    this.$emit('deleteJKContainerItem', this.declareId)
                    this.closeModal()
                    break
                case 'CK':
                    this.$emit('deleteCKContainerItem', this.declareId)
                    this.closeModal()
                    break
                case 'JJ':
                    this.$emit('deleteJKContainerItem', this.declareId)
                    this.closeModal()
                    break
                case 'CJ':
                    this.$emit('deleteCKContainerItem', this.declareId)
                    this.closeModal()
                    break
            }
        },

        // 删除单证信息
        deleteNumOfDocItem (type) {
            switch (type) {
                case 'JK':
                    this.$emit('deleteJKNumOfDocItem', this.declareId)
                    this.closeModal()
                    break
                case 'CK':
                    this.$emit('deleteCKNumOfDocItem', this.declareId)
                    this.closeModal()
                    break
                case 'JJ':
                    this.$emit('deleteJKNumOfDocItem', this.declareId)
                    this.closeModal()
                    break
                case 'CJ':
                    this.$emit('deleteCKNumOfDocItem', this.declareId)
                    this.closeModal()
                    break
            }
        }

    } // methods end
}
</script>

<style scoped>

</style>
